package org.karelun.gef.model;

import java.util.ArrayList;
import java.util.List;

import org.eclipse.draw2d.geometry.Dimension;
import org.eclipse.swt.graphics.RGB;

public class ClassModel extends Node {

    private static final long serialVersionUID = 3257847675427893304L;

    public static final String PROP_ATTRIBUTE = "ATTRIBUTE"; //$NON-NLS-1$
    
    public static final String PROP_METHOD="METHOD"; //$NON-NLS-1$

    private List<AttributeModel> attrModels=new ArrayList<AttributeModel>();
    
    private List<MethodModel> methodModels=new ArrayList<MethodModel>();

    private static int i=0;
    
    private String name="class"; //$NON-NLS-1$
    
    public ClassModel() {
        super();
        if(i>0)
        	name="class"+String.valueOf(i); //$NON-NLS-1$
        setText(name);
        i++;
        setSize(new Dimension(120,120));
      
        String id=String.valueOf(System.currentTimeMillis());
        setId(id);
        
        setForeColor(new RGB(0,0,0));
        setBgColor(new RGB(255, 255, 206));
    }
    
    public void addAttribute(AttributeModel model){
    	attrModels.add(model);
    	firePropertyChange(PROP_ATTRIBUTE, null, model);
    }
    
    public void removeAttribute(AttributeModel model){
    	attrModels.remove(model);
    	firePropertyChange(PROP_ATTRIBUTE, null, model);
    }
    
    public void addMethod(MethodModel model){
    	methodModels.add(model);
    	firePropertyChange(PROP_METHOD, null, model);
    }
    
    public void removeMethod(MethodModel model){
    	methodModels.remove(model);
    	firePropertyChange(PROP_METHOD, null, model);
    }
    
    public List<AttributeModel> getAttrModels() {
		return attrModels;
	}
    
    public List<MethodModel> getMethodModels() {
		return methodModels;
	}
    
//    public void addAttribute(BaseClassModel model) {
//        attributes.add(model);
//        if(model instanceof AttributeModel){
//        	attrModels.add((AttributeModel)model);
//        }else if(model instanceof MethodModel)
//        	methodModels.add((MethodModel)model);
//        firePropertyChange(PROP_ATTRIBUTE,null, model);
//    }
//
//    public void removeAttribute(BaseClassModel model) {
//    	if(attributes==null||attributes.isEmpty())
//    		return;
//        attributes.remove(model);
//        if(model instanceof AttributeModel)
//        	attrModels.remove((AttributeModel)model);
//        else if(model instanceof MethodModel)
//        	methodModels.remove((MethodModel)model);
//        firePropertyChange(PROP_ATTRIBUTE,null, model);
//    }
//    
//    public List<BaseClassModel> getAttributes() {
//        return attributes;
//    }
//    
//    public List<AttributeModel> getAttrModels(){
//    	return attrModels;
//    }
//    
//    public List<MethodModel> getMethodModels(){
//    	return methodModels;
//    }
//
//    public void setAttributes(List<BaseClassModel> attributes) {
//        this.attributes = attributes;
//    }

}